package com.ambow.store.service.impl;

import com.ambow.store.service.exception.ProductTypeException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ambow.store.entity.Product;
import com.ambow.store.service.ProductService;
import com.ambow.store.mapper.ProductMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author MyComputer
* @description 针对表【t_product】的数据库操作Service实现
* @createDate 2022-11-11 10:23:36
*/
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService{

    @Override
    public List<Product> getHostList() {
        LambdaQueryWrapper<Product> productLambdaQueryWrapper = new LambdaQueryWrapper<Product>();
        productLambdaQueryWrapper.orderByDesc(Product::getPriority).last("limit 4");
        List<Product> list = this.list(productLambdaQueryWrapper);
        return list;
    }

    @Override
    public Product getDataByID(Integer id) {
        LambdaQueryWrapper<Product> productLambdaQueryWrapper = new LambdaQueryWrapper<>();
        productLambdaQueryWrapper.eq(Product::getId,id);
        Product productData = this.getOne(productLambdaQueryWrapper);
        if (productData == null){
            throw new ProductTypeException("当前商品信息不存在");
        }
        return productData;
    }
}




